home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / examples / warp-sharp < prev    next >
Encoding:
Text File  |  2000-05-11  |  2.8 KB  |  93 lines

  1. #!/usr/bin/perl
  2.  
  3. # slightly edited by pcg@goof.com
  4.  
  5. use Gimp qw(:auto);
  6. use Gimp::Fu;
  7.  
  8. sub warp_sharp  {
  9.     my ($img, $drw, $edge_strength, $blur_strength,
  10.     $bump_depth, $displace_amount)=@_;
  11.     my $drawable_width=$drw->width;
  12.     my $drawable_height=$drw->height;
  13.     my $drawable_type=($drw->type);
  14.     my $edge_layer=gimp_layer_copy($drw,0);
  15.     my $x_displace_layer=
  16.       $img->layer_new($drawable_width, $drawable_height,
  17.               $drawable_type, "Displace X", 100, 0);
  18.     my $y_displace_layer=
  19.       $img->layer_new($drawable_width, $drawable_height,
  20.               $drawable_type, "Displace Y", 100, 0);
  21.     my @selection_info=$img->selection_bounds;
  22.     my $has_selection=$selection_info[0];
  23.     my $old_selection;
  24.     my $bump_xoff;
  25.     my $bump_yoff;
  26.     my $version=1;
  27.  
  28. #    Gimp::set_trace(TRACE_ALL);
  29.     $img->undo_push_group_start;
  30.     if ($has_selection) {
  31.         $old_selection=$img->gimp_selection_save;
  32.         $img->selection_grow($blur_strength + $bump_depth + $displace_amount);
  33.     $bump_xoff=$selection_info[1];
  34.     $bump_yoff=$selection_info[2];
  35.     }
  36.     $x_displace_layer->fill(1 + $version);
  37.     $y_displace_layer->fill(1 + $version);
  38.     $img->add_layer($edge_layer,-1);
  39.     $img->add_layer($x_displace_layer,-1);
  40.     $img->add_layer($y_displace_layer,-1);
  41.  
  42.     plug_in_edge($img,$edge_layer,$edge_strength,1);
  43.  
  44.     plug_in_gauss_iir($img, $edge_layer, $blur_strength, 1, 1)
  45.       if ($blur_strength >= 1);
  46.  
  47.     plug_in_bump_map($img,$x_displace_layer,$edge_layer, 0, 30,
  48.              $bump_depth, $bump_xoff,$bump_yoff, 0,0,0,0,0);
  49.  
  50.     plug_in_bump_map($img,$y_displace_layer,$edge_layer, 270, 30,
  51.              $bump_depth, $bump_xoff,$bump_yoff, 0,0,0,0,0);
  52.  
  53.     if ($has_selection) {
  54.     $old_selection->gimp_selection_load;
  55.     $old_selection->remove_channel;
  56.     # will cause a crash:
  57.     # $old_selection->gimp_channel_delete;
  58.     }
  59.  
  60.     plug_in_displace($img,$drw, $displace_amount, $displace_amount, 1,1,
  61.              $x_displace_layer, $y_displace_layer, 1);
  62.  
  63.     $img->remove_layer($edge_layer);
  64.     $img->remove_layer($x_displace_layer);
  65.     $img->remove_layer($y_displace_layer);
  66.     $img->undo_push_group_end; 
  67.     gimp_displays_flush();
  68.     return undef;
  69. }
  70.  
  71.  
  72. register
  73.   "plug_in_warp_sharp",
  74.   "Sharpen the current drawable",
  75.   "Sharpen the current drawable by squeezing unsharp edges. Algorithm described by Joern Loviscach in c't 22/1999, p 236.",
  76.   "Simon Budig <simon\@gimp.org>, Peter Daum <gator\@cs.tu-berlin.de>",
  77.   "Simon Budig, Peter Daum",
  78.   "2000-05-11",
  79.   N_"<Image>/Filters/Enhance/Warp Sharp...",
  80.   "RGB*, GRAY*",
  81.   [
  82.    [PF_SLIDER, "edge_detection", "Edge detection", 7, [1, 10, 0.1]],
  83.    [PF_SLIDER, "blur_radius", "Blur radius", 3, [0, 10, 0.1]],
  84.    [PF_SLIDER, "bump_depth", "Bump depth", 2, [1, 10, 1]],
  85.    [PF_SLIDER, "intensity", "Displace Intensity", 2.5, [0.1, 10, 0.1]]
  86.   ],
  87.   [],
  88.   ['gimp-1.1'],
  89.   \&warp_sharp;
  90.  
  91.  
  92. exit main;
  93.